from hyrobot.common import STEP, CHECK_POINT, INFO
from lib.webui_permission import *
import pyautogui
import pytest
import time
import json
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By

class c73254c:
    name = '产品管理员验证所有界面存在且可操作申请记录部分-c73254c'  # 需要将吕同学改为产品管理员测试用例名字

    # 初始化方法
    def setup(self):
        STEP(1, '登陆网站')
        driver = open_browser()
        productor2_login(driver)

    # 清除方法
    def teardown(self):
        driver = get_global_webdriver()
        driver.quit()

    # 测试用例步骤
    def teststeps(self):
        # 获取webdriver对象 对应 已经登录好的浏览器
        driver = get_global_webdriver()
        # driver = webdriver.Firefox()

        extending_button = driver.find_element_by_id("hamburger-container")
        try:
            driver.find_element(By.CLASS_NAME, "el-tooltip")
            extending_button.click()
        except:
            print("左侧栏没有隐藏")

        # click apply record
        time.sleep(1)
        apply_word2 = driver.find_element(By.XPATH,
                                          "/html/body/div/div/div[1]/ul/div[2]/a/li/span"
                                          )
        apply_word2.click()
        time.sleep(1)
        top_title1 = driver.find_element(By.XPATH,
                                         "/html/body/div/div/div[2]/div/div/div[2]/span/span[2]/span[1]/span"
                                         ).text
        CHECK_POINT("上方第2个标题对应", "申请记录" == top_title1)

        STEP(2, "页面跳转")
        turn_page(driver)

        STEP(3,"查询两个空")
        time.sleep(1)
        driver.find_element(By.XPATH,
        "/html/body/div/div/div[2]/section/div[1]/div/div/div[2]/form/div[3]/div/button/span"
                            ).click()
        # get table row num
        table_loc = driver.find_element(By.XPATH,
                                        "/html/body/div/div/div[2]/section/div[1]/div/div/div[2]/div[1]"
                                        )
        # 按行查询表格的数据，取出的数据是一整行，按空格分隔每一列的数据
        table_tr_list = table_loc.find_elements(By.TAG_NAME, 'tr')
        table_row_num = len(table_tr_list)
        CHECK_POINT("检查行数是否不为0",table_row_num >  0)

        STEP(4, "输入一条存在产品名称，项目名称的记录信息点击查询")
        project_name = "project37"
        product_name = "NAME--29"
        select_message_list(driver, project_name, product_name)
        got_db_manager_list = get_colum_list(driver, 3)
        for i in got_db_manager_list:
            INFO(i)
            CHECK_POINT("db管理员,提示信息是否一致", i == "111")

        STEP(5,"下载点击")
        # main ui button
        time.sleep(1)
        driver.find_element(By.CSS_SELECTOR,
                            "tr.el-table__row:nth-child(1) > td:nth-child(10) > div:nth-child(1) > button:nth-child(1) > span:nth-child(1)"
                            ).click()
        # inner button download
        time.sleep(3)
        driver.find_element(By.XPATH,
                            "/html/body/div[1]/div/div[2]/section/div[1]/div/div/div[5]/div/div[2]/div/div[1]/button/span"
                            ).click()
        download_a_file = check_file()
        CHECK_POINT("下载模板，检测下载文件名与数量", download_a_file[1].endswith(".iso") and download_a_file[0] == 1)

        # next button
        time.sleep(3)
        driver.find_element(By.XPATH,
                            "/html/body/div[1]/div/div[2]/section/div[1]/div/div/div[5]/div/div[2]/div/div[2]/button/span"
                            ).click()
        download_b_file = check_file()
        CHECK_POINT("下载模板，检测下载文件名与数量", download_b_file[1].endswith(".license") and download_b_file[0] == 1)

        # turn off
        time.sleep(3)
        INFO("CLOSE")
        driver.find_element(By.CSS_SELECTOR,
                            'div.el-dialog__footer:nth-child(3) > div:nth-child(1) > button:nth-child(1) > span:nth-child(1)'
                            ).click()
        # does it need to become a fun?

        STEP(6,"反馈")
        time.sleep(1)
        driver.find_element(By.XPATH,
        "/html/body/div/div/div[2]/section/div[1]/div/div/div[2]/div[1]/div[3]/table/tbody/tr[1]/td[10]/div/button[2]/span"
                            ).click()
        time.sleep(1)
        driver.find_element(By.CLASS_NAME,"el-textarea__inner").send_keys("some words")
        time.sleep(1)
        # concel
        driver.find_element(By.XPATH,
        "/html/body/div[1]/div/div[2]/section/div[1]/div/div/div[3]/div/div[3]/div/button[1]/span"
                            ).click()

        time.sleep(1)
        driver.find_element(By.XPATH,
                            "/html/body/div/div/div[2]/section/div[1]/div/div/div[2]/div[1]/div[3]/table/tbody/tr[1]/td[10]/div/button[2]/span"
                            ).click()
        time.sleep(1)
        driver.find_element(By.CLASS_NAME, "el-textarea__inner").send_keys("some words")
        time.sleep(1)
        driver.find_element(By.XPATH,
        "/html/body/div[1]/div/div[2]/section/div[1]/div/div/div[3]/div/div[3]/div/button[2]/span"
                            ).click()
        time.sleep(2)
        got_tip = driver.find_element(By.CLASS_NAME,
        "el-notification__content"
        ).text
        CHECK_POINT("提示信息是否一致",got_tip == "提交反馈成功")
        time.sleep(1)

        STEP(7, "查看详情")
        got_first_word = check_detail_apply(driver)
        expected_first_word = "申请记录信息"
        CHECK_POINT("提示信息是否一致", got_first_word == expected_first_word)

